#pragma once

#include "GeneralOrdering.h"

#include "OccurrenceSpecification.h"

namespace uml {

GeneralOrdering::GeneralOrdering(const QString& umlType)
    : NamedElement(umlType) {}

void GeneralOrdering::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    after_ = JsonSerializable::create<OccurrenceSpecification>(json.value("after"), errorList);

    before_ = JsonSerializable::create<OccurrenceSpecification>(json.value("before"), errorList);

}

void GeneralOrdering::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    if (after_) {
        QJsonObject after_json;
        after_->toJson(after_json);
        json.insert("after", after_json);
    }
    if (before_) {
        QJsonObject before_json;
        before_->toJson(before_json);
        json.insert("before", before_json);
    }
}

/// <summary>
/// after getter
/// The OccurrenceSpecification referenced comes after the OccurrenceSpecification
/// referenced by before.
/// </summary>
shared_ptr<OccurrenceSpecification> GeneralOrdering::after() const {
    return after_;
}

/// <summary>
/// after setter
/// The OccurrenceSpecification referenced comes after the OccurrenceSpecification
/// referenced by before.
/// </summary>
void GeneralOrdering::setAfter(shared_ptr<OccurrenceSpecification> value) {
    after_ = value;
}

/// <summary>
/// before getter
/// The OccurrenceSpecification referenced comes before the OccurrenceSpecification
/// referenced by after.
/// </summary>
shared_ptr<OccurrenceSpecification> GeneralOrdering::before() const {
    return before_;
}

/// <summary>
/// before setter
/// The OccurrenceSpecification referenced comes before the OccurrenceSpecification
/// referenced by after.
/// </summary>
void GeneralOrdering::setBefore(shared_ptr<OccurrenceSpecification> value) {
    before_ = value;
}

} // namespace uml
